#include "./BSP/SHT20/sht20.h"

float ReadSht20(unsigned char whatdo)                              //读取数据
{
	float temp;
  unsigned char MSB,LSB;
  float Humidity,Temperature;

	MyI2C_Start();   //起始信号
	MyI2C_SendByte(0x80); //发送一个字节
	if(MyI2C_ReceiveAck()==0) //等待应答
	{
		MyI2C_SendByte(whatdo); //字节发送
		if(MyI2C_ReceiveAck()==0)
		{
			do
			{
				delay_us(8);
				MyI2C_Start();
				MyI2C_SendByte(0x81);
			}while(MyI2C_ReceiveAck()==1);

			MSB = MyI2C_ReceiveByte();  //读取一个字节
			LSB = MyI2C_ReceiveByte();
			MyI2C_ReceiveByte(); 
			MyI2C_Stop();

			LSB &= 0xfc;
			temp = MSB*256 + LSB;

			if (whatdo==((unsigned char)0xf5))
    		{        
        		Humidity =(temp*125)/65536-6;

        		return Humidity;
    		}                                                                                                  
    		else      
    		{        
        		Temperature = (temp*175.72)/65536-46.85;

        		return Temperature; 
    		}
		}
	}

	return 0;
}

